#!/bin/bash

set -e
set -x

# 采集rpm包
# yum -y install docker-engine docker-compose --downloadonly --downloaddir=docker
# 在线安装
# yum -y install docker-engine docker-compose

bypy download docker.tgz

iplist_path=config
while read -r line
do
    case $line in
        *'#'*)
            continue
        ;;
        *'end'*)
            break
        ;;
        *)
            IFS=',' read -ra parts <<< "$line"
        ;;
    esac
    
    pass="${parts[0]}" 
    address="${parts[1]}"
    hostname="${parts[2]}"
    flag="${parts[3]}"
    
    if [ $address ];then
        sshpass -p$pass scp docker.tgz $address:/opt/docker.tgz
        sshpass -p$pass ssh -n $address tar xf /opt/docker.tgz -C /opt/
        sshpass -p$pass ssh -n $address yum -y --disablerepo='*' localinstall /opt/docker/*.rpm
        sshpass -p$pass scp daemon.json $address:/etc/docker/daemon.json
        sshpass -p$pass ssh -n $address systemctl restart docker
    fi
done < $iplist_path

set +x
set +e